package com.wt.springsamples.aop;

import com.wt.springsamples.annotation.AccessControl;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.security.access.prepost.PreAuthorize;

import java.lang.reflect.Method;

public class AopTest {

    public static void main(String[] args) {

//        for(Method m: AopService.class.getDeclaredMethods()){
//            PreAuthorize preAuthorize1 = AnnotationUtils.findAnnotation(m, PreAuthorize.class);
//            PreAuthorize preAuthorize2 = AnnotatedElementUtils.findMergedAnnotation(m, PreAuthorize.class);
//
//            System.out.println(preAuthorize1.value());
//            System.out.println(preAuthorize2.value());
//        }
//
        AbstractApplicationContext applicationContext = new AnnotationConfigApplicationContext(AopConfig.class);

        "".intern();
        //容器中返回的是AOP增强后的代理对象
        AopService aopService = applicationContext.getBean(AopService.class);
        int test = aopService.test(1);
    }
}
